package com.epam.android.training.day4day5.task1;

import android.content.res.Resources;
import android.os.Bundle;

/**
 * Utility class to operate with application resources.
 * 
 * @author Anton Novikau
 *
 */
public final class ResourcesUtil {

    /**
     * Creates an instance of ResourcesUtil. Private constructor to avoid
     * instantiation of utility class.
     */
    private ResourcesUtil() {

    }

    /**
     * Formats greeting message from resource bundle and given data.
     * 
     * @param resources set of application resources to find message template
     * @param data bundle data to use in message construction
     * @return formatted greeting string ready to be shown on UI
     */
    public static String formatGreeting(Resources resources, Bundle data) {
        String firstNameKey = resources.getString(R.string.first_name_bundle_key);
        String lastNameKey = resources.getString(R.string.last_name_bundle_key);
        String greetingBundle = resources.getString(R.string.greeting);

        return String.format(greetingBundle, data.getString(firstNameKey),
                data.getString(lastNameKey));
    }
    
    /**
     * Formats users age message from resource bundle and given data.
     * @param resources resources set of application resources to find message template
     * @param age age of user to use in message construction
     * @return formatted age message string ready to be shown on UI
     */
    public static String formatAgeMessage(Resources resources, int age) {
        
        return String.format(resources.getString(R.string.your_age_message), age);
    }
}
